package com.hzdesk.media.koreabatchmatvector.logic.view;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hzdesk.media.koreabatchmatvector.R;
import com.hzdesk.media.koreabatchmatvector.bean.MouseUserDevicesinfoBean;
import com.hzdesk.media.koreabatchmatvector.logic.contract.MouseSetContract;
import com.hzdesk.media.koreabatchmatvector.logic.persenter.MouseSetPersenter;
import com.hzdesk.media.koreabatchmatvector.matvector.NiceSpinner;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/7/9.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 * <p>
 * TODO: 2018/7/10                                                                               鼠标设置
 */

public class MouseSetActivity extends BaseActivity implements MouseSetContract.IMouseSetView {
    @BindView(R.id.activity_mouse_set_tv_number)
    TextView activityMouseSetTvNumber;
    @BindView(R.id.activity_mouse_set_checkbox)
    CheckBox activityMouseSetCheckbox;
    @BindView(R.id.activity_mouse_set_et_name)
    EditText activityMouseSetEtName;
    @BindView(R.id.activity_mouse_set_nice_spinner_one)
    NiceSpinner activityMouseSetNiceSpinnerOne;
    @BindView(R.id.activity_mouse_set_nice_spinner_two)
    NiceSpinner activityMouseSetNiceSpinnerTwo;
    @BindView(R.id.activity_mouse_set_tv_cancle)
    TextView activityMouseSetTvCancle;
    @BindView(R.id.activity_mouse_set_tv_confirm)
    TextView activityMouseSetTvConfirm;
    @BindView(R.id.activity_mouse_set_ll_bg)
    LinearLayout activityMouseSetLlBg;

    private MouseSetPersenter mMouseSetPersenter = new MouseSetPersenter(this);
    private int item_postion;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mouse_set);
        ButterKnife.bind(this);
        item_postion = getIntent().getIntExtra("item_postion", 0);
        mMouseSetPersenter.initDate(activityMouseSetNiceSpinnerOne, activityMouseSetNiceSpinnerTwo, this);
        mMouseSetPersenter.setinitListener(activityMouseSetCheckbox, this, item_postion);
    }

    @OnClick({R.id.activity_mouse_set_tv_cancle, R.id.activity_mouse_set_tv_confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.activity_mouse_set_tv_cancle:
                mMouseSetPersenter.onClickCancle();
                break;
            case R.id.activity_mouse_set_tv_confirm:
                mMouseSetPersenter.onClickConfirm(this);
                break;
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        final SharedPreferences mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        int selector = mSharedPreferences.getInt("item_skin", 0); //todo 名称
        activityMouseSetLlBg.setBackgroundResource(updateBg[selector]);
    }

    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        item_postion = intent.getIntExtra("item_postion", 0);
    }

    @Override
    public void setupdateView(MouseUserDevicesinfoBean userBean) {
        activityMouseSetEtName.setText(userBean.getName());
    }

    @Override
    public void setOneSelectedIndex(int index) {
        activityMouseSetNiceSpinnerOne.setSelectedIndex(index);
    }

    @Override
    public void setTwoSelectedIndex(int index) {
        activityMouseSetNiceSpinnerTwo.setSelectedIndex(index);
    }

    @Override
    public String getEtName() {
        return activityMouseSetEtName.getText().toString().trim();
    }

    @Override
    public void toFinshPager() {
        finish();
    }


    @Override
    public void setTvNumber(String msg) {
        activityMouseSetTvNumber.setText(msg);
    }

    @Override
    public String getMouseSetName() {
        return activityMouseSetEtName.getText().toString().trim();
    }

    @Override
    public void setMouseSetName(String name) {
        activityMouseSetEtName.setText(name);
    }
}
